/*
 * @Author: iy88 
 * @Date: 2020-05-02 11:50:27 
 * @Last Modified by: iy88
 * @Last Modified time: 2020-10-24 21:25:47
 */
const nodemailer = require('nodemailer');

/**
 * send to mailBox
 * @param {string} email
 * @param {string} subject
 * @param {string} msg
 * @param {Function} callback
 */

function create(transConfig) {
  const transporter = nodemailer.createTransport(transConfig);
  return function (to, subject, context) {
    if (context.html) {
      return new Promise((resolve, reject) => {
        transporter.sendMail({ from: transConfig.auth.user, to, subject, text: context.text, html: context.html }, (err, info) => {
          !err ? resolve(info) : reject(err);
        })
      })
    } else {
      return new Promise((resolve, reject) => {
        transporter.sendMail({ from: transConfig.auth.user, to, subject, text: context.text, html: context.html }, (err, info) => {
          !err ? resolve(info) : reject(err);
        })
      })
    }
  }
}
// create({
//   host: 'smtp.163.com', // smtp.qq.com
//   port: 465,
//   secure: true,
//   auth: {
//     user: "sfbrywj@163.com", // 1845767798@qq.com
//     pass: "Sfbrywj1223" // vwcavwkbjivlcehj
//   }
// })
module.exports = create